package com.wjp.villagemp.service.impl.manage;

import com.wjp.villagemp.mapper.manage.StudentMapper;
import com.wjp.villagemp.model.manage.StudentEntity;
import com.wjp.villagemp.service.manage.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Jacob
 * @Date: 2019/1/21 09:38
 * @Description:
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<StudentEntity> listStudent(int pageSize, int start, String studentName) {
        return studentMapper.listStudent(pageSize, start, studentName);
    }

    @Override
    public Integer countStudent(String studentName) {
        return studentMapper.countStudent(studentName);
    }

    @Override
    public Integer insertStudent(StudentEntity studentEntity) {
        int key = 0;
        try {
            key = studentMapper.insert(studentEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return key;
    }

    @Override
    public Integer updateStudent(StudentEntity studentEntity) {
        int key = 0;
        try {
            key = studentMapper.updateByPrimaryKey(studentEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return key;
    }

    @Override
    public Integer removeStudent(Integer studentNum) {
        int key = 0;
        try {
            key = studentMapper.deleteByPrimaryKey(studentNum);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return key;
    }

    @Override
    public List<StudentEntity> listAllStudent() {
        List<StudentEntity> stuList = null;
        try {
            stuList = studentMapper.selectAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return stuList;
    }

    @Override
    public boolean studentNumHasRep(String studentNum) {
        Integer rep = studentMapper.studentNumHasRep(studentNum);
        if (rep > 0) {
            return true;
        }
        return false;
    }
}
